/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package runebound.ui.mapa;

import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;
import runebound.manejadores.RBControladorJuego;
import runebound.manejadores.eventos.RBEventoMovimiento;

/**
 *
 * Control del mapa
 * @author Miguel (alakat@gmail.com)
 */
public class MouseMapaListener implements MouseListener{

    private RBMapaPanel mapaPanel ;

    public MouseMapaListener(RBMapaPanel mapaPanel) {
        this.mapaPanel = mapaPanel;
    }
    
    
    
    @Override
    public void mouseClicked(MouseEvent e) {
        
        
        Point p = e.getPoint();
        TileMapa tm = this.mapaPanel.getTile(p);
        
        if(tm==null){
//            System.out.println("Click en "+tm.getX()+","+tm.getY());
//            System.err.println("No tile");
        }else{
            
            List<TileMapa> vecinos = this.mapaPanel.getVecinosPorTile(this.mapaPanel.getTileActivo());
            //TODO Comprobar el estado del juego. 
            if(vecinos.contains(tm)){
                RBEventoMovimiento evento = new RBEventoMovimiento(RBControladorJuego.getInstance().getHeroeActivo(), tm, this.mapaPanel.getTileActivo());
                RBControladorJuego.getInstance().recibirEvento(evento);
            }
            
        }
        
        
    }

    @Override
    public void mousePressed(MouseEvent e) {
        
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        
    }

    @Override
    public void mouseExited(MouseEvent e) {
        
    }
    
}
